#include "stdafx.h"
#include "ListAdit.h"


CListAdit::CListAdit()
{

}
CListAdit::~CListAdit()
{

}


int CListAdit::getCount()
{
	return m_listInfo.GetCount();
}

void CListAdit::getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
	if (pItem->GetChildrenCount() == 0)
	{
		pItem->InitFromXml(xmlTemplate);
	}
	SOFTINFO *psi = m_listInfo.GetData() + position % m_listInfo.GetCount();
	pItem->FindChildByName(L"txt_index")->SetWindowText(SStringT().Format(_T("%d"), position+1));
	pItem->FindChildByName(L"txt_sid")->SetWindowText(psi->rfIDname);
	pItem->FindChildByName(L"txt_editpath")->SetWindowText(psi->editpath);
	pItem->FindChildByName(L"txt_checkpath")->SetWindowText(psi->checkpath);
	pItem->FindChildByName(L"txt_releasepath")->SetWindowText(psi->releasepath);
	pItem->FindChildByName(L"txt_size")->SetWindowText(psi->rfIDSize);


}

SStringW CListAdit::GetColumnName(int iCol) const
{
	return SStringW().Format(L"col%d", iCol + 1);
}

int CListAdit::AddItem(SOFTINFO data)
{
	m_listInfo.Add(data);
	notifyDataSetChanged();
	return 1;
}

int CListAdit::InsertItem(int index, const SOFTINFO data)
{
	m_listInfo.Add(data);
	notifyDataSetChanged();
	return 1;


	return 0;
}

void CListAdit::DeleteItem(int iPosition)
{

	if (iPosition >= 0 && iPosition < getCount())
	{
		int iItem = iPosition % m_listInfo.GetCount();
		m_listInfo.RemoveAt(iItem);
		notifyDataSetChanged();
	}

}

SStringW CListAdit::GetItemText(int row, int lie)
{
	if (getCount() <= 0) return _T("");
	SStringW tmp;
	tmp = m_listInfo[row].rfIDname;
	return tmp;
}

int CListAdit::GetColOfIndex(int index)
{
	int i = 0;
	for (; i < getCount(); i++)
	{
		if (index == m_listInfo[i].iIndex)
		{
			return  i + 1;
		}
	}
	return -1;
}
